

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.weso.lodin.appserv.DatasetAppServ;
import org.weso.lodin.appserv.TransformerAppServ;
import org.weso.lodin.appserv.WorldBankAppServ;
import org.weso.lodin.dao.CountryDAO;
import org.weso.lodin.dao.CountryDAOImpl;
import org.weso.lodin.dao.WorldBankDataDAOImpl;
import org.weso.lodin.generated.Indicator;
import org.weso.lodin.to.CompleteModelTO;
import org.weso.lodin.to.DatasetTO;
import org.weso.lodin.utils.PrefixManager;
import org.weso.lodin.utils.TransformerHelper;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;


public class WorldBankAppServMain {

	public static void main(String []args) throws IOException{
		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
		InputStream inCountries = contextClassLoader.getResourceAsStream(
				TransformerAppServ.COUNTRIES_COUNTRIES_FAO_XLS);
		List<String> sources = new LinkedList<String>();
		sources.add("xml/wb/AG.LND.TOTL.K2.xml");
		sources.add("xml/wb/IT.NET.USER.P2.xml");
		sources.add("xml/wb/NY.GDP.PCAP.CD.xml");
		sources.add("xml/wb/SH.DYN.CHLD.FE.xml");
		sources.add("xml/wb/SH.DYN.MORT.xml");		
		sources.add("xml/wb/SH.STA.MMRT.xml");
		sources.add("xml/wb/SP.POP.TOTL.xml");
		sources.add("xml/wb/SH.XPD.PCAP.xml");
		sources.add("xml/wb/SP.RUR.TOTL.ZS.xml");
		sources.add("xml/wb/SP.DYN.LE00.IN.xml");		
		sources.add("xml/wb/SP.POP.0014.TO.ZS.xml");
		CountryDAO daoCountries = new CountryDAOImpl(inCountries);
		WorldBankAppServ transformer = new WorldBankAppServ(new WorldBankDataDAOImpl(),daoCountries);
		ResourceBundle mapPrefixesURIs = PrefixManager.getResourceBundle();		
		String outputFile = "wb-observations.ttl";
		CompleteModelTO result = transformer.createRDFModelFromDataset(sources);
		Model observations = result.getObservations();
//		System.out.println(observations.listObjectsOfProperty(
//				observations.getResource("http://data.webfoundation.org/webindex/observation/external/obs2294"), 
//				observations.getProperty(TransformerAppServ.ONTOLOGY_BASE_URI+"value")).next().asLiteral().
//				getDouble());
		TransformerHelper.serializeModel(observations,
				mapPrefixesURIs,IndicatorsAppServMain.DIR_GENERATED+File.separator+outputFile);		
		
	}

}

